package 链表和树.链表;
//Java：相交链表
public class IntersectionOfTwoLinkedLists{
    public static void main(String[] args) {
        Solution solution = new IntersectionOfTwoLinkedLists().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
//    public class ListNode {
//        int val;
//        ListNode next;
//        ListNode() {}
//        ListNode(int val) { this.val = val; }
//        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
//    }
public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode curA = headA;
        ListNode curB = headB;
        //p = p != null ? p.next : headB;
        //q = q != null ? q.next : headA;
        while(curA != curB){
            if(curA != null){
                curA = curA.next;
            }else {
                curA = headB;
            }
            if(curB != null){
                curB = curB.next;
            }else {
                curB = headA;
            }
        }
        return curA;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}